window.onload= function(){
	window.JSBridge.showlocalData();

	$("#fucbox").change(function() {
			var boxstate=document.getElementById("fucbox");
			if(boxstate.checked==false){
				swal("已经关闭任务栏通知","实验性功能关闭","error");
			}else{
				if(1){
				swal("已经开启任务栏通知","实验性功能开启","success");
				//swal(""+jiaoxuezhou());
				getDayclass(3);
				}else{
					swal("xxxxxxxx", "xxxxxxx", "error");
					boxstate.checked=false;
				}
			}
	});
}
function set_jw_account(acc){
	$("#jiaowuID").html(acc);
	$("#jw_dl_btn").css("display","none");
	$("#jw_tc_btn").css("display","");
}
function set_xxmh_account(acc){
	$("#xxmhID").html(acc);
	$("#xxmh_dl_btn").css("display","none");
	$("#xxmh_tc_btn").css("display","");
}
function reloadClass(){
	swal({
	  title: "重载课表将清除您自定义的课程",
	  text: "您手动添加的课程将无法找回，是否继续?",
	  icon: "warning",
	  buttons: true,
	  dangerMode: true,
	})
	.then((willDelete) => {
		if (willDelete) {
			window.JSBridge.getUserdata();
	  } else {
		//swal("Your imaginary file is safe!");
	  }
	});

}
function java_savedata(data){
	try{
		  var xhr = new XMLHttpRequest();
		  xhr.open("get", "https://api.iou.ink/HFUTcourse/"+data, true);
		  xhr.onreadystatechange = function() {
		    if (xhr.readyState == 4 && xhr.status == 200) {
		      //console.log(xhr.responseText);
		      var user_data0= eval('(' + xhr.responseText.replace(/\None/g,"'None'").replace(/\True/g,"'True'").replace(/\False/g,"'False'") + ')');
              var user_data = eval('(' + user_data0 + ')');
              var str_jsonData = JSON.stringify(user_data);
			  rwLS("w","str_jsonData",str_jsonData);
			  swal("请求课表信息成功,如果未自动刷新请退出重进","","success");
			  setTimeout("window.location.reload();", 1500)
		    }
		  };
		  xhr.send(null);
		  swal("正在请求课表信息");
	}
	catch(e)//IE
	{alert(e)}
}
function checkupdate(thisversion,versionName){
	//打开时检查更新
	swal('正在检查更新');
	var thisversion =Number(thisversion);
	var script3=document.createElement('script');
	script3.setAttribute('type','text/javascript');
	script3.setAttribute('src','https://iou.ink/file/api/update.js?ID='+String(randomNum(10000,99999)));
	document.head.appendChild(script3);
	script3.onload=script3.onreadystatechange=function(){
		if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete'){
			var lastVersion =Number(update_json.lastVersion);
			if( lastVersion > thisversion){
				swal({
					title: "检测到新版本",
					text: "当前版本:"+versionName+"\n最新版本:"+update_json.versionName+"\n更新内容:"+update_json.content+"\n更新日期:"+update_json.lastDate,
					icon: "warning",
					buttons:{
						cancel: "暂不更新",
						update: {
							text: "立即更新",
							value: "update",
						}
					},
				})
				.then((value) => {
					switch (value) {
						case "update":
							window.location.href=update_json.updateUrl;
							break;
						default:
							//swal("Got away safely!");
					}
				});
			}else{
				swal({
					title: "已经是最新版本",
					text: "当前版本:"+versionName+"\n最新版本:"+update_json.versionName+"\n更新内容:"+update_json.content+"\n更新日期:"+update_json.lastDate,
					//icon: "https://xn--15t.top/img/toux.jpg",
					icon: "success",
					button: "确定",
				});

			}
		}
	}
}

function rwLS(str,key,value){
	if(str == 'r'){
		return localStorage.getItem(key);
	}else if(str == 'w'){
		localStorage.setItem(key,value);
		return 1;
	}else if(str == 'rm'){
		localStorage.removeItem(key);
		return 2;
	}
}

function randomNum(minNum,maxNum){
    switch(arguments.length){
        case 1:
            return parseInt(Math.random()*minNum+1,10);
        break;
        case 2:
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
        break;
            default:
                return 0;
            break;
    }
}